﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;
using SchoolBusiness;

namespace SchoolAdministration
{
    public partial class StaffLoan : System.Web.UI.Page
    {
        private readonly BlStaff _blstaff = new BlStaff();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadAllStaff();
            }
        }

        protected void BtnLoan_Click(object sender, EventArgs e)
        {
            Loan _loan = new Loan();
            _loan.LoanAmount =Convert.ToInt32(TxtLaonAmount.Text);
            _loan.interestRate = Convert.ToInt32(txtInterest.Text);
            _loan.staffId = int.Parse(DDLStaff.SelectedValue.ToString());
            _loan.appliedDate = Convert.ToDateTime(txtDate.Text);
            int resutlt = _blstaff.SaveLoanAmount(_loan);
            if (resutlt > 0)
            {
                Helper.Alert.Show("Successfull");
            }
                
        }
        private void LoadAllStaff()
        {
            List<Staff> Lstaff = new List<Staff>();
            Lstaff = _blstaff.GetAllStaff();
            DDLStaff.Items.Clear();
            DDLStaff.Items.Insert(0, new ListItem("--Staff--", "0"));
            DDLStaff.DataSource = Lstaff;
            DDLStaff.DataTextField = "FirstName";
            DDLStaff.DataValueField = "StaffId";
            DDLStaff.DataBind();
        
        }
    }
}